/**
 * Copyright (c) 2024-2025 National Fundamental Software of China Co., Ltd.
 *
 * You should have find a copy of NFSChina License. If not, please contact us
 * by email <os_support@nfschina>
 *
**/

import QtQuick 2.7
import QtQuick.Controls 2.0 as QQC2
import QtQuick.Controls.impl 2.12
import org.kde.plasma.core 2.0 as PlasmaCore
QQC2.Slider {
    id: control
 
    property bool acceptWheel: true //滚轮滑动
    property color handleBorderColor: "#CCCCCC"     //按钮边框颜色
    property color handleNormalColor: "#FFFFFF"  //按钮颜色

    property color handleHoverColor: Qt.lighter(handleNormalColor)
    property color handlePressColor: Qt.darker(handleNormalColor)


    property color completeColor: PlasmaCore.Theme.highlightColor
    property color incompleteColor: "#E6E6E6"
 
 
    implicitWidth: horizontal? 192: 4;
    implicitHeight: horizontal? 4: 192;
    //padding把长条背景挤压
    padding: horizontal? height/4: width/4;
 
    handle: Rectangle {
        x: control.leftPadding + (control.horizontal ? control.visualPosition * (control.availableWidth - width) : (control.availableWidth - width) / 2)
        y: control.topPadding + (control.horizontal ? (control.availableHeight - height) / 2 : control.visualPosition * (control.availableHeight - height))
        width: 14
        height: 14
        color: control.pressed
               ?handlePressColor
               :control.hovered
                 ?handleHoverColor
                 :handleNormalColor
        border.width: 1
        radius:7
        border.color: handleBorderColor
        Rectangle{
            anchors.centerIn:parent
            width:6
            height:6
            radius:3
            color:completeColor
        }
    }
 
    background: Rectangle {
        x: control.leftPadding + (control.horizontal ? 0 : (control.availableWidth - width) / 2)
        y: control.topPadding + (control.horizontal ? (control.availableHeight - height) / 2 : 0)
        implicitWidth: horizontal? 192: 4;
        implicitHeight: horizontal? 4: 192;
        width: control.horizontal ? control.availableWidth : implicitWidth
        height: control.horizontal ? implicitHeight : control.availableHeight
        radius: 3
        color: control.incompleteColor
        scale: control.horizontal && control.mirrored ? -1 : 1
 
        //用另一个方块分别已完成和未完成的颜色
        Rectangle {
            y: control.horizontal ? 0 : control.visualPosition * parent.height
            width: control.horizontal ? control.position * parent.width : parent.width
            height: control.horizontal ? parent.height : control.position * parent.height
            radius: 3
            color: control.completeColor
        }
    }
    MouseArea{
        anchors.fill: parent
        //避免和handle冲突
        acceptedButtons: Qt.NoButton
        onWheel: {
            if(wheel.angleDelta.y<0){
                control.decrease();
            }else{
                control.increase();
            }
        }
    }
}